﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace PrintDemo.DBUtil
{
    public class ValidDbSettingRule
    {
        /// <summary>
        /// 验证数据库设置
        /// </summary>
        /// <param name="opdSetting">数据库设置参数</param>
        /// <returns>连接成功返回true，否则返回false</returns>
        public static bool ValidDBSetting(DBConnSetting opdSetting)
        {
            bool success = true;
            MySqlConnection conn = null;
            try
            {
                MySqlHelper helper = new MySqlHelper(opdSetting.Server, opdSetting.DbName, opdSetting.User, opdSetting.Psw);
                conn = helper.getConnection();
                if (conn == null)
                {
                    success = false;
                }
            }
            catch
            {
                success = false;
            }
            finally
            {
                if (conn != null)
                    conn.Close();
            }
            return success;

        }
    }
}
